package Java语言.数据结构.互转.Object数组和Int数组;

import java.util.Arrays;

public class ObjectArray2IntArray {
    public static void main(String[] args) {
        //从Object[]转到int[]，从包装类型转过来同理
        Object[] o = new Object[]{1, 2, 3};
        int[] t=convertFromObject(o);
        System.out.println(Arrays.toString(t));
        //int[]转到Object[],Integer同理
        int[] t2 = new int[]{1, 2, 3};
        Object[] o2 = convertToObject(t2);
        System.out.println(Arrays.toString(o2));
    }

    static int[] convertFromObject(Object[] from) {
        if (null != from) {
            int[] to = new int[from.length];
            for (int i = 0; i < to.length; i++) {
                to[i] = (int)from[i];

            }
            return to;
        }
        else return null;
    }
    static Object[] convertToObject(int[] from) {
        if (null != from) {
            Object[] to = new Object[from.length];
            for (int i = 0; i < to.length; i++) {
                to[i] = from[i];

            }
            return to;
        }
        else return null;
        
    }
}
